/* Archive Extractor
 * Copyright 2008-2009 Matthew Hoops
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $URL: http://archive-extractor.googlecode.com/svn/trunk/binhex.cpp $
 * $Id: binhex.cpp 2 2009-03-23 01:29:43Z clone2727 $
 *
 */

#include "binhex.h"

BinHexArchive::BinHexArchive() : StandardArchive() {
}

std::vector<const char*> BinHexArchive::getArchiveExtensions() {
	std::vector<const char*> exList;
	exList.push_back("hqx");
	return exList;
}

int BinHexArchive::detect(FILE* file) {
	char strBuf[45 + 1];
	fread(strBuf, 1, 45, file);
	strBuf[45] = 0;
	if (!strcmp(strBuf, "(This file must be converted with BinHex 4.0)"))
		return 100;
	return 0;
}

bool BinHexArchive::extractFiles(FILE* file) {
	fseek(file, 45, SEEK_SET); // Skip opening comment
	
	// Let's test our line endings.
	readByte(file); // Skip the first one
	byte endLineSkip = 1; 
	if (readByte(file) != ':') { // Data always begins with 
		endLineSkip = 2;
		readByte(file);
	}
	
	// FIXME!
	return false;
	
	byte buf[64];
	byte temp = 0;
	byte bits = 0;
	while (!feof(file)) {
		fread(buf, 1, 64, file);
		byte *ptr = buf;
		while (ptr - buf < 64) {
			if (*ptr == ':')
				break;
			
		}
		
		if (*ptr == ':')
			break;
	}
	
	return false;
}
